/*
 * ESPrimitive.java - ScriptME
 * 
 * Copyright (c) 2009 Cesar Henriques <cesar at alttab.com.ar>.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Lesser Public License v2.1
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
 * 
 * Based on FESI Project
 * 
 * Contributors:
 * 	Jean-Marc Lugrin - initial API and implementation
 * 	Cesar Henriques <cesar at alttab.com.ar> - J2ME Porting and Extensions
 */
package org.scriptme.ecmascript.data;

import org.scriptme.ecmascript.exceptions.EcmaScriptException;

/**
 * This is the superclass of all primitive values (non object) of FESI. The
 * conversion to a primitive value from a primitive value is always the same
 * value, independently of the hint (9.1).
 * <P>
 * Use the isPrimitive function, so that further primitive could be added
 * without subclassing this class.
 */
public abstract class ESPrimitive extends ESValue {

	/**
	 * Create a new primitive value. Does not add any specific information.
	 */
	public ESPrimitive() {
		super();
	}

	/**
	 * Indicate that this value is a primitive value, useful for various tests
	 * in conversions. This avoid testing the type, in case additional
	 * primitives must be created.
	 * 
	 * @return true
	 */
	public final boolean isPrimitive() {
		return true;
	}

	/**
	 * Return false to indicate that this value is not composite.
	 * 
	 * @return false
	 */
	public boolean isComposite() {
		return false;
	}

	/**
	 * Convert to a primitive - a NOOP for a primitive.
	 * 
	 * @return this
	 * 
	 * @throws EcmaScriptException
	 *             the ecma script exception
	 * 
	 * @exception EcmaScriptException
	 *                not thrown
	 */
	public final ESValue toESPrimitive() throws EcmaScriptException {
		return this;
	}

	/**
	 * Convert to a primitive - a NOOP for a primitive.
	 * 
	 * @param hint
	 *            the hint
	 * 
	 * @return this
	 * 
	 * @throws EcmaScriptException
	 *             the ecma script exception
	 * 
	 * @exception EcmaScriptException
	 *                not thrown
	 */
	public final ESValue toESPrimitive(int hint) throws EcmaScriptException {
		return this;
	}

	/**
	 * Returns a full description of the value, with the specified name.
	 * 
	 * @param name
	 *            The name of the value to describe
	 * 
	 * @return the description of this value
	 */
	public ValueDescription getDescription(String name) {
		return new ValueDescription(name, "PRIMITIVE", this.toString());
	}
}
